package com.commons.tools.utils;

import javax.servlet.http.*;
import java.io.*;

public class FileUtils {

    public static void getOutFileStream(InputStream inputStream, HttpServletResponse response){

        BufferedInputStream bis = null;
        try {
            byte[] buffer = new byte[1024];
            bis = new BufferedInputStream(inputStream);
            OutputStream os = response.getOutputStream();
            int i = bis.read(buffer);
            while (i != -1) {
                os.write(buffer, 0, i);
                i = bis.read(buffer);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (bis != null) {
                try {
                    bis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
